var e = require("../../../../@babel/runtime/helpers/toConsumableArray"), a = require("../../../../@babel/runtime/helpers/createForOfIteratorHelper"), l = require("../../../../@babel/runtime/helpers/defineProperty"), t = getApp();

Page({
    data: {
        isTotal: !1,
        showLevelId: "",
        showLevelElId: "levelEl",
        showLevelName: "level_",
        levels: [],
        memberOfLevel: {},
        totalMemberCount: 0,
        levelPagination: {},
        defaultLevelName: ""
    },
    onLoad: function(e) {
        var a = JSON.parse(wx.getStorageSync("mailLanguage")).agent, l = a.agent_num || "客户数量";
        e.type && (l = a.agent_count || "总客户数量", this.setData({
            isTotal: !0
        })), wx.setNavigationBarTitle({
            title: l
        }), this.getLevelMembers();
    },
    onReachBottom: function() {
        this.getLevelMembers();
    },
    switchLevelTab: function(e) {
        var a = this, l = e.currentTarget.dataset;
        this.setData({
            showLevelId: l.id,
            showLevelElId: "levelEl" + l.id,
            showLevelName: "level_" + l.id
        }, function() {
            0 === a.data.memberOfLevel["level_" + l.id].length && a.getLevelMembers();
        });
    },
    getLevelMembers: function() {
        var i = this;
        wx.showLoading({
            title: "加载中"
        });
        var n = this.data.showLevelId, r = "level_" + n, s = this.data.levelPagination[r], o = null;
        if (o = this.data.isTotal ? t.getNetAddresss("plugin.member-center-agent.api.index.my-agent-all") : t.getNetAddresss("plugin.member-center-agent.api.index.my-agent"), 
        "" !== n && (o += "&level_id=" + n), s) {
            if (o += "&page=" + s.page, !0 === s.finished || !0 === s.loading) return void wx.hideLoading();
            this.setData(l({}, "levelPagination." + r + ".loading", !0));
        }
        t._getNetWork({
            url: o,
            success: function(l) {
                var t = l.data, n = t.result, o = t.data, d = t.msg;
                0 === n && wx.showToast({
                    title: d,
                    icon: "none",
                    duration: 1500,
                    mask: !1,
                    success: function(e) {
                        setTimeout(function() {
                            wx.redirectTo({
                                url: "/packageD/member/myRelationship/myRelationship"
                            });
                        }, 1500);
                    }
                });
                var v = {};
                if (0 === i.data.levels.length) {
                    v.levels = o.level, v.memberOfLevel = {
                        level_0: []
                    }, v.levelPagination = {};
                    var g, m = 0, h = a(o.level);
                    try {
                        for (h.s(); !(g = h.n()).done; ) {
                            var u = g.value;
                            v.memberOfLevel["level_" + u.id] = [], v.levelPagination["level_" + u.id] = {
                                loading: !1,
                                finished: !1,
                                page: 1
                            }, m += u.yz_member_count;
                        }
                    } catch (e) {
                        h.e(e);
                    } finally {
                        h.f();
                    }
                    v.levelPagination.level_ = {
                        loading: !1,
                        finished: !1,
                        page: 2
                    }, v.memberOfLevel[r] = o.child.data, v.totalMemberCount = m, v.defaultLevelName = o.default_level_name;
                } else {
                    var c = i.data.memberOfLevel[r];
                    c.push.apply(c, e(o.child.data)), v["memberOfLevel." + r] = c, v["levelPagination." + r + ".page"] = s.page + 1;
                }
                (o.child.data.length < o.child.per_page || 0 === o.child.data.length) && (v["levelPagination." + r + ".finished"] = !0), 
                v["levelPagination." + r + ".loading"] = !1, i.setData(v), wx.hideLoading();
            }
        });
    }
});